//
//  EditBianjiView.m
//  Gxj
//
//  Created by 💋索少杰 on 2017/9/8.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "EditBianjiView.h"
#import <SDAutoLayout.h>
#import "GXJPrefix.pch"

@interface EditBianjiView ()<UITextViewDelegate,UITextFieldDelegate>

#define Start_X          155.0f      // 第一个按钮的X坐标
#define Start_Y          78.0f     // 第一个按钮的Y坐标
#define Width_Space      5.0f      // 2个按钮之间的横间距
#define Height_Space     20.0f     // 竖间距
#define Button_Height   15.0f    // 高
#define Button_Width    30.0f    // 宽

@end

@implementation EditBianjiView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor=[UIColor whiteColor];
        
        
        [self addSubview:self.biaotiText];
        [self addSubview:self.xiahuxianLab];
        [self addSubview:self.zhutiText];
        [self addSubview:self.biaoqianBut];
        [self addSubview:self.downchoice];
        [self addSubview:self.xiahuxianLab1];
        
        [self addSubview:self.positiveTF];
        [self addSubview:self.imagePositiveLine];
        [self addSubview:self.positiveTV];
        [self addSubview:self.negativeTF];
        [self addSubview:self.negativeTV];
        [self addSubview:self.imageNegativeLine];
        [self addSubview:self.secantLine];
        
        [self showEditStromView];
    }
    return self;
}
- (void)showEditStromView{
    
    _biaotiText.sd_layout
    .topSpaceToView(self, kHeightScale(10))
    .leftSpaceToView(self, kWidthScale(10))
    .rightSpaceToView(self, kWidthScale(10))
    .heightIs(kHeightScale(50));
    
    _xiahuxianLab.sd_layout
    .topSpaceToView(_biaotiText, kHeightScale(2))
    .leftSpaceToView(self, 0)
    .rightSpaceToView(self, 0)
    .heightIs(kHeightScale(1));
    
    _zhutiText.sd_layout
    .topSpaceToView(self.xiahuxianLab, kHeightScale(15))
    .leftSpaceToView(self, kWidthScale(10))
    .widthIs(kWidthScale(148))
    .autoHeightRatio(0);
    
    _downchoice.sd_layout
    .topSpaceToView(self.xiahuxianLab, kHeightScale(17))
    .rightSpaceToView(self, kWidthScale(10))
    .widthIs(kWidthScale(10))
    .heightIs(kHeightScale(10));
    
    _xiahuxianLab1.sd_layout
    .topSpaceToView(self.zhutiText, kHeightScale(15))
    .leftSpaceToView(self, 0)
    .rightSpaceToView(self, 0)
    .heightIs(kHeightScale(1));
    
    _positiveTF.sd_layout
    .topSpaceToView(self.xiahuxianLab1,kHeightScale(5))
    .leftEqualToView(self.biaotiText)
    .rightEqualToView(self.biaotiText)
    .heightIs(kHeightScale(50));
    
    _imagePositiveLine.sd_layout
    .topSpaceToView(self.positiveTF,kHeightScale(3))
    .leftEqualToView(self.positiveTF)
    .rightEqualToView(self.positiveTF)
    .heightIs(kHeightScale(1));
    
    _positiveTV.sd_layout
    .topSpaceToView(self.imagePositiveLine,kHeightScale(10))
    .leftEqualToView(self.imagePositiveLine)
    .rightEqualToView(self.imagePositiveLine)
    .heightIs(kHeightScale(130));
    
    _secantLine.sd_layout
    .topSpaceToView(self.positiveTV,kHeightScale(10))
    .leftSpaceToView(self,0)
    .rightSpaceToView(self,0)
    .heightIs(0.5);
    
    _negativeTF.sd_layout
    .topSpaceToView(self.secantLine,kHeightScale(10))
    .leftEqualToView(self.positiveTV)
    .rightEqualToView(self.positiveTV)
    .heightIs(kHeightScale(50));
    
    _imageNegativeLine.sd_layout
    .topSpaceToView(self.negativeTF,kHeightScale(3))
    .leftEqualToView(self.negativeTF)
    .rightEqualToView(self.negativeTF)
    .heightIs(kHeightScale(1));
    
    _negativeTV.sd_layout
    .topSpaceToView(self.imageNegativeLine,kHeightScale(10))
    .leftEqualToView(self.negativeTF)
    .rightEqualToView(self.negativeTF)
    .heightIs(kHeightScale(130));

}
- (UITextField *)biaotiText
{
    if (!_biaotiText)
    {
        _biaotiText = [[UITextField alloc] init];
        _biaotiText.placeholder = @"请输入辩论标题（必填）";
//        [_biaotiText setValue:@"请输入辩论标题" forKeyPath:@"_placeholderLabel.text"];
//        [_biaotiText setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
        _biaotiText.delegate = self;
        _biaotiText.font=[UIFont systemFontOfSize:kWidthScale(22)];
    }
    return _biaotiText;
}
- (UILabel *)xiahuxianLab
{
    if (!_xiahuxianLab)
    {
        _xiahuxianLab= [[UILabel alloc] init];
        _xiahuxianLab.backgroundColor = [UIColor lightGrayColor];
    }
    return _xiahuxianLab;
}
- (UILabel *)zhutiText
{
    if (!_zhutiText)
    {
        _zhutiText=[[UILabel alloc] init];
        _zhutiText.text=@"请选择相应标签（选填）";
        _zhutiText.textColor=[UIColor blackColor];
        _zhutiText.font=[UIFont systemFontOfSize:kWidthScale(13)];
    }
    return _zhutiText;
}
- (UIButton *)biaoqianBut
{
    if (!_biaoqianBut)
    {
        //商业标签
        NSArray*arr=@[@"shangye",@"fuzhuang",@"UI"];
        for (int i = 0 ; i < arr.count; i++) {
            NSInteger index = i % arr.count;
            NSInteger page = i / arr.count;
            
            // 圆角按钮
            _biaoqianBut = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            _biaoqianBut.tag = i;//这句话不写等于废了
            _biaoqianBut.frame = CGRectMake(index * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Width_Space )+Start_Y, Button_Width, Button_Height);
            [_biaoqianBut setBackgroundImage:[UIImage imageNamed:arr[index]] forState:UIControlStateNormal];
            [self addSubview:_biaoqianBut];
        }
    }
    return _biaoqianBut;
}
//选择标签按钮
- (UIButton *)downchoice
{
    if (!_downchoice)
    {
        _downchoice=[[UIButton alloc] init];
        _downchoice.backgroundColor=[UIColor lightGrayColor];
        [_downchoice setImage:[UIImage imageNamed:@"xiala"] forState:UIControlStateNormal];
    }
    return _downchoice;
}
- (UILabel *)xiahuxianLab1
{
    if (!_xiahuxianLab1)
    {
        _xiahuxianLab1= [[UILabel alloc] init];
        _xiahuxianLab1.backgroundColor = [UIColor lightGrayColor];;
    }
    return _xiahuxianLab1;
}

- (UITextField *)positiveTF
{
    if (!_positiveTF)
    {
        _positiveTF = [[UITextField alloc] init];
        _positiveTF.placeholder = @"请输入正方观点：";
    }
    return _positiveTF;
}
- (UITextField *)negativeTF
{
    if (!_negativeTF)
    {
        _negativeTF = [[UITextField alloc] init];
        _negativeTF.placeholder = @"请输入反方观点：";
    }
    return _negativeTF;
}
- (UIImageView *)imagePositiveLine
{
    if (!_imagePositiveLine)
    {
        _imagePositiveLine = [[UIImageView alloc] init];
        _imagePositiveLine.image = [UIImage imageNamed:@"hui"];
    }
    return _imagePositiveLine;
}
- (UITextView *)positiveTV
{
    if (!_positiveTV)
    {
        _positiveTV = [[UITextView alloc] init];
        _positiveTV.layer.borderWidth = 0.5;
        _positiveTV.layer.borderColor = [UIColor purpleColor].CGColor;
        _positiveTV.layer.cornerRadius = 12;
        _positiveTV.layer.masksToBounds = YES;
        _positiveTV.textContainerInset = UIEdgeInsetsMake( kHeightScale(15), kWidthScale(15), 30, 30);
        _positiveTV.text = @"请对正方观点进行阐述（选填）";
        _positiveTV.tag = 11111111;
        _positiveTV.textColor = [UIColor lightGrayColor];
        _positiveTV.font = [UIFont systemFontOfSize:kWidthScale(15)];
        _positiveTV.delegate = self;
    }
    return _positiveTV;
}
- (UIImageView *)imageNegativeLine
{
    if (!_imageNegativeLine)
    {
        _imageNegativeLine = [[UIImageView alloc] init];
        _imageNegativeLine.image = [UIImage imageNamed:@"hui"];
    }
    return _imageNegativeLine;
}
- (UITextView *)negativeTV
{
    if (!_negativeTV)
    {
        _negativeTV =[[ UITextView alloc] init];
        _negativeTV.layer.borderWidth = 0.5;
        _negativeTV.layer.borderColor = [UIColor blueColor].CGColor;
        _negativeTV.layer.cornerRadius = 12;
        _negativeTV.layer.masksToBounds = YES;
        _negativeTV.textContainerInset = UIEdgeInsetsMake( kHeightScale(15), kWidthScale(15), 30, 30);
        _negativeTV.text = @"请对反方观点进行阐述（选填）";
        _negativeTV.tag = 22222222;
        _negativeTV.textColor = [UIColor lightGrayColor];
        _negativeTV.font = [UIFont systemFontOfSize:kWidthScale(15)];
        _negativeTV.delegate = self;
    }
    return _negativeTV;
}
- (UILabel *)secantLine
{
    if (!_secantLine)
    {
        _secantLine = [[UILabel alloc] init];
        _secantLine.backgroundColor = [UIColor lightGrayColor];
    }
    return _secantLine;
}


- (void)textViewDidEndEditing:(UITextView *)textView
{
    switch (textView.tag) {
        case 11111111:
            if ([_positiveTV.text isEqualToString:@""]) {
                _positiveTV.text = @"请对正方观点进行阐述（选填）";
                _positiveTV.textColor = [UIColor lightGrayColor];
            }
            else{
                _positiveTV.text = _positiveTV.text;
                _positiveTV.textColor = [UIColor blackColor];
            }
            break;
            
        case 22222222:
            if ([_negativeTV.text isEqualToString:@""]) {
                _negativeTV.text = @"请对反方观点进行阐述（选填）";
                _negativeTV.textColor = [UIColor lightGrayColor];
            }
            else{
                _negativeTV.text = _negativeTV.text;
                _negativeTV.textColor = [UIColor blackColor];
            }
            break;
            
        default:
            break;
    }
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    switch (textView.tag) {
        case 11111111:
            if ([_positiveTV.text isEqualToString:@"请对正方观点进行阐述（选填）"]) {
                _positiveTV.text=@"";
                _positiveTV.textColor=[UIColor blackColor];
            }
            else{
                _positiveTV.text = _positiveTV.text;
                _positiveTV.textColor = [UIColor blackColor];
            }
            break;
            
        case 22222222:
            if ([_negativeTV.text isEqualToString:@"请对反方观点进行阐述（选填）"]) {
                _negativeTV.text=@"";
                _negativeTV.textColor=[UIColor blackColor];
            }
            else{
                _negativeTV.text = _negativeTV.text;
                _negativeTV.textColor = [UIColor blackColor];
            }
            break;
            
        default:
            break;
    }
}


@end
